package vashion.azeroth.api.controller.item;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vashion.azeroth.activity.manager.GlobalActivityInfoManager;
import vashion.azeroth.api.controller.base.BaseController;
import vashion.azeroth.contant.ItemErrorEnum;
import vashion.azeroth.core.activity.GlobalActivityExtendInfoDO;
import vashion.azeroth.core.activity.GlobalActivityInfoDO;
import vashion.azeroth.core.activity.query.ActivityExtendQueryDO;
import vashion.azeroth.core.activity.query.ActivityInfoQueryDO;
import vashion.azeroth.core.result.ApiResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动服务接口
 *
 * @param <T>
 */
@Controller
@RequestMapping("/api/activity")
public class ActivityController<T> extends BaseController {

    private final static Logger log = LoggerFactory.getLogger(ActivityController.class);

    @Autowired
    private GlobalActivityInfoManager globalActivityManager;


    @RequestMapping("getActivityList.htm")
    @ResponseBody
    public ApiResult<List<GlobalActivityInfoDO>> getActivityList(ModelMap modelMap,
                                                                 HttpServletResponse response,
                                                                 HttpServletRequest request,
                                                                 @ModelAttribute("activityInfoQueryDO")
                                                                 ActivityInfoQueryDO activityInfoQueryDO) {
        try {
            return globalActivityManager.queryAllActivityByType(activityInfoQueryDO);
        } catch (Exception e) {
            log.error("globalActivityManager.createGlobalActivity error", e);
            return ApiResult.newErrorResult(ItemErrorEnum.SYSTEM_ERROR.getErrorCode(), ItemErrorEnum.SYSTEM_ERROR.getErrorMessage());
        }
    }

    @RequestMapping("queryExtendList.htm")
    @ResponseBody
    public ApiResult<List<GlobalActivityExtendInfoDO>> queryExtendList(ModelMap modelMap,
                                                                       HttpServletResponse response,
                                                                       HttpServletRequest request,
                                                                       @ModelAttribute("activityExtendQueryDO")
                                                                       ActivityExtendQueryDO activityExtendQueryDO) {
        try {
            return globalActivityManager.queryEffectExtendInfoList(activityExtendQueryDO);
        } catch (Exception e) {
            log.error("globalActivityManager.createGlobalActivity error", e);
            return ApiResult.newErrorResult(ItemErrorEnum.SYSTEM_ERROR.getErrorCode(), ItemErrorEnum.SYSTEM_ERROR.getErrorMessage());
        }
    }
}
